package com.guigu.www.erp.yinjiaxiong.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.www.erp.common.dao.SPayMapper;
import com.guigu.www.erp.common.pojo.PageVo;
import com.guigu.www.erp.common.pojo.SGather;
import com.guigu.www.erp.common.pojo.SPay;
import com.guigu.www.erp.yinjiaxiong.service.YJXSPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class YJXSPayServiceImpl implements YJXSPayService {
    @Autowired
    SPayMapper sPayMapper;

    @Override
    public int insertSGather(SPay sPay) {
        //生成入库编号 入库单编号	401+当前日期+4位流水号
        String time="402";
        //用于登记时间
        SimpleDateFormat fom=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String format2 = fom.format(date);


        //用于组成入库编号
        SimpleDateFormat format=new SimpleDateFormat("yyyyMMdd");
        String format1 = format.format(date);
        time+=format1;
        System.out.println("format1==="+format1);
        //查询上一条最大编号
        String s =sPayMapper.getMaxPayId();
        //System.out.println("s======="+s);
        //查询最大编号的方法
        if (s==null){
            time+="0001";
        }else {
            Integer i = Integer.parseInt(s.substring(11));
            i++;
            String str=i+"";
            if (str.length()==1){
                str="000"+str;
            }else if (str.length()==2){
                str="00"+str;
            }else if (str.length()==3){
                str="0"+str;
            }
            time+=str;
        }

        //System.out.println("time========="+time);
        sPay.setPayId(time);
        sPay.setRegisterTime(format2);
        sPay.setCheckTag("0");//审核标记为0
        sPay.setStoreTag("1");//库存标记已登记
        //System.out.println("sPay======"+sPay);
        return sPayMapper.insertSelective(sPay);
    }

    @Override
    public PageVo<SPay> getsPaycheck_tag0(SPay sPay, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SPay> list = sPayMapper.getsPaycheck_tag0(sPay);
        PageInfo<SPay> pageInfo = new PageInfo<>(list);
        PageVo<SPay> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        //System.out.println("pageVo----------"+pageVo);
        return pageVo;
    }

    @Override
    public int updateSPaycheckTag(SPay sPay) {
        return sPayMapper.updatecheckTagByPrimaryKey(sPay);
    }

    @Override
    public PageVo<SPay> getAllSPay(SPay sPay, Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        List<SPay> list = sPayMapper.getAllSPay(sPay);
        PageInfo<SPay> pageInfo = new PageInfo<>(list);
        PageVo<SPay> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        //System.out.println("pageVo----------"+pageVo);
        return pageVo;
    }

    @Override
    public PageVo<SPay> getSpaycheckTag1storeTag1(SPay sPay, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SPay> list = sPayMapper.getSpaycheckTag1storeTag1(sPay);
        PageInfo<SPay> pageInfo = new PageInfo<>(list);
        PageVo<SPay> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        //System.out.println("pageVo----------"+pageVo);
        return pageVo;
    }

    @Override
    public int updateSGatherattemper(Integer id) {
        SPay sPay = new SPay();
        Date date = new Date();
        //获取当前时间
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        sPay.setId(id);
        sPay.setAttemper("尹家雄");
        sPay.setAttemperTime(format);
        //System.out.println("修改入库表的时间=========="+sPay);
        //System.out.println("");
        return sPayMapper.updateByPrimaryKeySelective(sPay);
    }

    @Override
    public int ByIdupdatesGatherstoreTag(Integer id) {
        return sPayMapper.ByIdupdatesGatherstoreTag(id);
    }

    @Override
    public int ByspayIdupdatesgatheredAmount(Integer parentId, Integer sumAmount) {
        return sPayMapper.ByspayIdupdatesgatheredAmount(parentId,sumAmount);
    }

    @Override
    public PageVo<SPay> getspaystoreTag2(SPay sPay, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SPay> list = sPayMapper.getspaystoreTag2(sPay);
        PageInfo<SPay> pageInfo = new PageInfo<>(list);
        PageVo<SPay> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        //System.out.println("pageVo----------"+pageVo);
        return pageVo;
    }

    @Override
    public PageVo<SPay> getspaystoreTag3(SPay sPay, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SPay> list = sPayMapper.getspaystoreTag3(sPay);
        PageInfo<SPay> pageInfo = new PageInfo<>(list);
        PageVo<SPay> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        //System.out.println("pageVo----------"+pageVo);
        return pageVo;
    }

    @Override
    public void updatecheckerAndcheckTime(SPay sPay) {
        sPay.setChecker("尹家雄");
        Date date = new Date();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        sPay.setCheckTime(format);
        //System.out.println("复核数据==="+sPay);
        sPayMapper.updateByPrimaryKeySelective(sPay);
    }

    @Override
    public int ByspayIdupdatesgatheredAmountandstoreTag4(Integer id, Integer sumAmount) {
        return sPayMapper.ByspayIdupdatesgatheredAmountandstoreTag4(id,sumAmount);
    }

    @Override
    public PageVo<SPay> getAllSgetSpaystoreTagGreater2Pay(SPay sPay, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SPay> list = sPayMapper.getAllSgetSpaystoreTagGreater2Pay(sPay);
        PageInfo<SPay> pageInfo = new PageInfo<>(list);
        PageVo<SPay> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        //System.out.println("pageVo----------"+pageVo);
        return pageVo;
    }
}
